package cn.tedu;

import java.sql.*;

public class Demo03 {
    public static void main(String[] args) throws SQLException {
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3307/empdb?characterEncoding=utf8&serverTimezone=Asia/Shanghai","root","147258bb");
        System.out.println("链接对象:"+conn);
        Statement s= conn.createStatement();
        //插入数据SQl
       // s.executeUpdate("insert  into emp(name) values('tom')");
        //执行修改的SQL
//        s.executeUpdate("update  emp set name='jerry' where name='tom'");
        //执行删除的SQL
//        s.executeUpdate("delete from emp where name='jerry'");
        //执行查询的SQL
        ResultSet rs = s.executeQuery("select name ,sal from emp");
        while (rs.next()){
//            String name = rs.getString("name");
//            double sal = rs.getDouble("sal");
            //通过查询回来数据的位置获取数据
            String name = rs.getString(1);
            double sal = rs.getDouble(2);
            System.out.println(name+":"+sal);
        }
        System.out.println("执行完毕!");
        conn.close();

    }
}
